#!/usr/bin/env python

import sys

def main():
	list = sorted(["Foo Fighters", "Eagles of Death Metal", "Queens of the Stone Age", "Elbow"], key=str.lower)
	
	first = 0;
	last = len(list)
	pointer = (last - first) / 2

	print "There are " + str(len(list)) + " items in the list"

	searchterm = sys.argv[1]

	failurecount = 0

	while True:
		if failurecount >= 3:
			print "Not found"
			sys.exit(1)
		if (last - first) < 2:
			failurecount = failurecount + 1
		if searchterm == list[pointer]:
			print "Found at " + str(list.index(searchterm)+1)
			sys.exit(0)
		elif searchterm > list[pointer]:
			first = pointer
			pointer = ((last - first) / 2) + first
		elif searchterm < list[pointer]:
			last = pointer
			pointer = ((last - first) / 2) + first

if __name__ == "__main__":
	main()
